home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 1RLSL1G (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  2.1 KB  |  30 lines

  1. package com.ibm.uvm.abt.edit;
  2.  
  3. import java.awt.Point;
  4. import java.beans.PropertyEditorSupport;
  5. import java.util.ResourceBundle;
  6.  
  7. public class PointPropertyEditor extends PropertyEditorSupport {
  8.    private static ResourceBundle resabtedit = ResourceBundle.getBundle("com/ibm/uvm/abt/edit/abtedit");
  9.  
  10.    public String getAsText() {
  11.       return ((PropertyEditorSupport)this).getValue() instanceof String ? (String)((PropertyEditorSupport)this).getValue() : ((Point)((PropertyEditorSupport)this).getValue()).x + ", " + ((Point)((PropertyEditorSupport)this).getValue()).y;
  12.    }
  13.  
  14.    public String getJavaInitializationString() {
  15.       Point value = (Point)((PropertyEditorSupport)this).getValue();
  16.       return value == null ? "new java.awt.Point(0,0)" : "new java.awt.Point(" + value.x + ", " + value.y + ")";
  17.    }
  18.  
  19.    private Point parseForPoint(String text) throws Exception, NumberFormatException {
  20.       int x = text.indexOf(",");
  21.       if (x < 0) {
  22.          throw new Exception(resabtedit.getString("x_and_y_must_be_sep"));
  23.       } else {
  24.          String yText = text.substring(x + ",".length());
  25.          String xText = text.substring(0, x);
  26.          return new Point(Integer.valueOf(xText.trim()), Integer.valueOf(yText.trim()));
  27.       }
  28.    }
  29. }
  30.